package com.android.settings.audio.peq.util;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.media.AudioManager;
import android.util.Log;

import java.util.ArrayList;
import java.util.Locale;

/**
 * Created by Administrator on 2019/9/29.
 */

public class DspUtil {
    static DspUtil util;
    public ArrayList<String> list = new ArrayList<>();
    private AudioManager mAudioManager;
    private String[] languageString = {"en_us", "zh_cn", "zh_hk", "ja", "default"};

    private DspUtil() {
    }

    public static DspUtil getInstance() {
        if (util == null) {
            util = new DspUtil();
        }
        return util;
    }

    public int getLangusgecode(Context context) {
        String appLanguageCurrent = getAPPLanguageCurrent(context);
        int languagecode;
        switch (appLanguageCurrent) {
            case "en-us":
                languagecode = 0;
                break;
            case "zh-cn":
                languagecode = 1;
                break;
            case "zh-hk":
            case "zh-tw":
            case "zh-mo":
                languagecode = 2;
                break;
            case "ja-jp":
                languagecode = 3;
                break;
            default:
                languagecode = 4;
        }
        return languagecode;
    }

    private String getAPPLanguageCurrent(Context context) {
        Locale locale = Locale.getDefault();
        Resources res = context.getResources();
        Configuration config = res.getConfiguration();
        String language = locale.getLanguage();
        String country = config.locale.getCountry();
        language = language + "-" + country;
        Log.i("DspUtil", "Get app Language : " + language);
        return language.toLowerCase();
    }

    private String getLanguageString(int langusgecode) {
        return languageString[langusgecode];
    }
}
